/* 二进制IO */
#include <stdio.h>
#include <stdlib.h>


int main() {
    float data[10];
    for (int i = 0; i < 10; ++i){
        data[i] = 1.0f + 0.1f * i;
    }

    
    FILE* fp = fopen("./bfile", "w+");
    if (!fp) {
        perror("fopen fail");
        exit(1);
    }

    if (fwrite(&data[2], sizeof(float), 4, fp) != 4) {
        perror("fwrite error");
        exit(1);
    }

     for (int i = 0; i < 10; ++i){
        data[i] = 0;
    }

    fp = freopen("./bfile", "r", fp);
    int n = fread(data, sizeof(float), 4, fp);
    printf("read %d data from file: \n", n);

    for (int i = 0; i < 10; ++i)  {
        printf("%f, ", data[i]);
    }
    printf("\n");

    fclose(fp);

    return 0;
}
